package com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.useroption;

import com.alstudio.module.xmpp.protocol.xmpp.data.ALXmppData;
import com.alstudio.module.xmpp.protocol.xmpp.packact.ALXmppDomainConfig;
import com.alstudio.module.xmpp.protocol.xmpp.packact.IQNameSpace;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.AlXmlTag;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate;
import com.alstudio.utils.encode.ALDES;

/**
 * 绑定邮箱iq
 * 
 * @author alonso lee
 * 
 */
public class BindEmailIQCreator extends BaseIQTemplate {

	String email, pwd;

	public BindEmailIQCreator(String email, String pwd, String domain) {
		// TODO Auto-generated constructor stub
		this.domain = domain;
		this.email = email;
		this.pwd = pwd;
	}

	@Override
	public String getIQXml() {
		// TODO Auto-generated method stub

		to = ALXmppDomainConfig.getALXmppDomainConfig().getDomainByNameSpace(
				IQNameSpace.NS_BIND_EMAIL);
		mALIQCreator.setTo(to + domain);
		mALIQCreator.setNs(IQNameSpace.NS_BIND_EMAIL);
		mALIQCreator.setType(IQ_TYPE_SET);

		// 旧密码
		AlXmlTag tag = new AlXmlTag("email");
		try {
			tag.setText(ALDES.encryptDES(email, ALXmppData.DES_KEY));
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		tagList.add(tag);

		// 新密码
		tag = new AlXmlTag("password");
		try {
			tag.setText(ALDES.encryptDES(pwd, ALXmppData.DES_KEY));
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		tagList.add(tag);

		String xml = "";
		try {
			xml = mALIQCreator.getXml();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return xml;

	}

}
